/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: wfqueue_manager.hpp
 */

#ifndef _WFQUEUE_MANAGER_HPP_
#define _WFQUEUE_MANAGER_HPP_

#include <iostream>
#include <string>

#include "workflow.hpp"
#include "wfqueue.hpp"
#include "synqueue.cpp"

using namespace middleware::queueing;

//-----------------------------------------------------------------------------
// Enum, struct, aliases

//-----------------------------------------------------------------------------
// Constants
namespace middleware {
/*!
 * Defines the upper limit of the queue.
 */
const unsigned int kMaxWorkflowsInQueue = 25;
}
//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*!
 * Manages the queue of workflows between UI and Manager. It resides in
 * manager.
 */
class WFQueueManager : public WFQueue {
public:
	typedef SynQueue<Workflow, kMaxWorkflowsInQueue>::Reference
			WorkflowReference; /* Reference to a workflow */
	typedef const SynQueue<Workflow, kMaxWorkflowsInQueue>::ConstReference
			WorkflowConstReference; /* Const reference to a workflow */
	/*!
	 * Constructs a new WFQueueManager with an empty queue of workflows.
	 */
	WFQueueManager();
	/*!
	 * Destructor.
	 */
	~WFQueueManager();
	/*!
	 * Enqueues a workflow.
	 */
	void enqueue(WorkflowConstReference workflow);
	/*!
	 * Dequeues a workflow.
	 */
	WorkflowConstReference dequeue();
protected:
	/*!
	 * Synchronized queue of workflows. Limit = kMaxWorkflowsInQueue.
	 */
	SynQueue<Workflow, kMaxWorkflowsInQueue> _workflows_queue;
private:

}; /* WFQueueManager */
} /* middleware */

#endif
